<template>
      <div>
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item>订单管理</el-breadcrumb-item>
          <el-breadcrumb-item>订单列表</el-breadcrumb-item>
        </el-breadcrumb>

<!--        卡片区域-->
        <el-card>
<!--          搜索区域-->
          <el-row>
            <div style="margin-top: 15px;">
              <el-col :span="8">
                <el-input placeholder="请输入内容" v-model="ordersparams.query">
                <el-button slot="append" icon="el-icon-search" @click="selectorders"></el-button>
              </el-input>
              </el-col>
            </div>
          </el-row>

<!--          表格区域-->
          <el-table :data="orderslist" border stripe>
                <el-table-column type="index" label="#"></el-table-column>
                <el-table-column  label="订单编号" prop="order_number" width="300px"></el-table-column>
                <el-table-column  label="订单价格" prop="order_price"></el-table-column>
                <el-table-column  label="是否付款" prop="order_pay" >
                  <template slot-scope="slot">
                    <el-button v-if="slot.row.order_pay === '0'" size="small" style="background-color: #9f312c;color: red">未付款</el-button>
                    <el-button v-else-if="slot.row.order_pay === '1'" size="small">已付款</el-button>
                  </template>
                </el-table-column>
                <el-table-column  label="是否发货" prop="is_send"></el-table-column>
                <el-table-column  label="下单时间" prop="create_time">
                  <template slot-scope="scope">
                    {{scope.row.create_time | dataFormat}}
                  </template>
                </el-table-column>
                <el-table-column  label="操作">
                  <el-button type="primary" icon="el-icon-edit" size="small" @click="editorders"></el-button>
                  <el-button type="success" icon="el-icon-location" size="small" @click="ck_data"></el-button>
                </el-table-column>
          </el-table>


<!--          分页模块-->
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="ordersparams.pagenum"
            :page-sizes="[5, 10, 20, 50]"
            :page-size="ordersparams.pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="400">
          </el-pagination>
        </el-card>

<!--        编辑的对话框 -->
        <el-dialog
          title="编辑"
          :visible.sync="editdialogVisible"
          width="50%">

          <el-form :model="editruleForm" :rules="editrules" ref="editruleForm" label-width="100px" class="demo-ruleForm">
            <el-form-item label="省市区/县" prop="ssx">
              <el-cascader
                v-model="editruleForm.ssx"
                :options="fldata"
                @change="edithandleChange"  clearable></el-cascader>
            </el-form-item>
            <el-form-item label="详细地址" prop="xxdz">
              <el-input v-model="editruleForm.xxdz"></el-input>
            </el-form-item>
          </el-form>

                    <span slot="footer" class="dialog-footer">
              <el-button @click="editdialogVisible = false">取 消</el-button>
              <el-button type="primary" @click="editdialogVisible = false">确 定</el-button>
            </span>
        </el-dialog>


<!--        查看物流信息-->
        <el-dialog
          title="物流信息"
          :visible.sync="ckdialogVisible"
          width="50%">

          <el-timeline :reverse="true">
            <el-timeline-item
              v-for="(activity, index) in wlxx"
              :key="index"
              :timestamp="wlxx.ftime" >
              {{activity.context}}
            </el-timeline-item>
          </el-timeline>


          <span slot="footer" class="dialog-footer">
          <el-button @click="ckdialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="ckdialogVisible = false">确 定</el-button>
  </span>
        </el-dialog>

      </div>
</template>

<script>
import fldata from './citydata'
import htwlxx from './wlsj'
export default {
  data() {
    return {
      searchdata: '', // 搜索输入框的数据绑定
      // 配置获取订单数据列表的参数
      ordersparams: {
        query: '', // 查询参数
        pagenum: 1, // 当前页码
        pagesize: 5, // 每页显示条数
        user_id: '', // 用户id
        pay_status: '', // 支付状态
        is_send: '', // 是否发货
        order_fapiao_title: [], // ['个人','公司']
        order_fapiao_company: '', // 公司名称
        order_fapiao_content: '', // 发票内容
        consignee_addr: '',  //发货地址
      },
      total: '',  //存储订单总数
      orderslist: [], // 存储订单数据
      editdialogVisible: false, // 编辑的对话框控制
      fldata,   // 存储级联选择器的数据
      ckdialogVisible: false,  // 查看物流信息的对话框控制器
      editruleForm: {  // 存储了编辑的表单数据
        ssx: '',
        xxdz: ''
      },
      wlxx: [], // 存储了物流信息
      editrules: {
        ssx: [
          { required: true, message: '请选择', trigger: 'blur' }
        ],
        xxdz: [
          { required: true, message: '请输入详细地址', trigger: 'blur' }
        ],
      }
  }},
  created() {
    // 调用获取订单管理函数
    this.getorderslist()
  },
  methods: {
    async getorderslist() {
      const {data: res} = await this.$http.get(`orders`,{params: this.ordersparams})
      if (res.meta.status !== 200) return this.$message.error('获取订单数据列表失败')
      this.orderslist = res.data.goods
      this.total = res.data.total
    },
    handleSizeChange(pagesize) {  // 当pagesize,每页显示多少数据发送改变
      this.ordersparams.pagesize = pagesize
      this.getorderslist()
    },
    handleCurrentChange(pagenum) {  // 当pagenum,当前页面值发生改变
      this.ordersparams.pagenum = pagenum
      this.getorderslist()
    },
    editorders() {
      this.editdialogVisible = !this.editdialogVisible
    },
    edithandleChange(a) {  // 没有接口,放弃

    },
    async ck_data() {
      this.ckdialogVisible = !this.ckdialogVisible
      // 发起获取物流信息的axios请求
      this.wlxx = htwlxx[0].data
      this.$message.success('获取物流信息成功')
      console.log(this.wlxx)
    },
    selectorders() {
      console.log(this.ordersparams.query)
      console.log(this.ordersparams)
      this.getorderslist()
    }
  }
}
</script>

<style scoped>
.el-breadcrumb {
  margin: 0 0 15px 15px;
}
.el-pagination {
  margin-top: 10px;
}
.el-table {
  margin-top: 20px;
}
</style>
